package org.mall.litemall.wx.util;

import java.util.Objects;

/**
 * 维护用户token
 */
public class UserTokenManager {

    /**
     * 生成用户token
     * @param id
     * @return
     */
	public static String generateToken(Integer id) {
        JwtHelper jwtHelper = new JwtHelper();
        return jwtHelper.createToken(id);
    }

    /**
     * 根据token获取用户id
     * @param token
     * @return
     */
    public static Integer getUserId(String token) {
    	JwtHelper jwtHelper = new JwtHelper();
    	Integer userId = jwtHelper.verifyTokenAndGetUserId(token);
    	if(Objects.isNull(userId) || Objects.equals(0,userId)){
    		return null;
    	}
        return userId;
    }
}
